<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form">
            <div class="layui-form-item">

                <div class="layui-form-item">
                        <label class="layui-form-label">导航名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="nav_name" lay-verify="required" autocomplete="off" class="layui-input" value="{$info.nav_name}">
                        </div>
                </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属位置</label>
                        <div class="layui-input-inline">
                            <select name="nav_seat" lay-verify="required" lay-search="" lay-filter="seat">
                                <option value="">直接选择或搜索选择</option>
                                <option value="1" {if $info.nav_seat == 1}selected{/if} >顶部导航</option>
                                <option value="2" {if $info.nav_seat == 2}selected{/if} >底部导航</option>
                                <option value="3" {if $info.nav_seat == 3}selected{/if} >左侧导航</option>
                                <option value="4" {if $info.nav_seat == 4}selected{/if} >右侧导航</option>
                                <option value="5" {if $info.nav_seat == 5}selected{/if} >快捷导航</option>
                                <option value="6" {if $info.nav_seat == 6}selected{/if} >主导航</option>
                            </select>
                        </div>
                    </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">导航类型</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="nav_type" lay-filter="type" value="1" title="跳转" {if $info.nav_type == 1}checked{/if} >
                        <input type="radio" name="nav_type" lay-filter="type" value="2" title="多级" {if $info.nav_type == 2}checked{/if} >
                    </div>
                </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">所属导航</label>
                        <div class="layui-input-inline">
                            <select name="pid" lay-verify="required" lay-search="" id="nav">
                                <option value="0" {if $info.pid == 0}selected{/if} >顶级导航</option>
                                {if !empty($navs)}
                                    {volist name="$navs" id="ns"}
                                        <option value="{$ns.nav_id}" {if $info.pid == $ns.nav_id}selected{/if} >{$ns.nav_name}</option>
                                    {/volist}
                                {/if}
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item" id="path">
                        <label class="layui-form-label">导航路径</label>
                        <div class="layui-input-inline">
                            <input type="text" name="nav_path" autocomplete="off" class="layui-input" placeholder="#" value="{$info.nav_path}">
                        </div>
                    </div>

                    <div class="layui-form-item" id="path_type">
                        <label class="layui-form-label">跳转方式</label>
                        <div class="layui-input-block">
                            <input type="radio" name="path_type" value="1" title="在本窗口打开" {if $info.path_type == 1}checked{/if} >
                            <input type="radio" name="path_type" value="2" title="另开一个窗口" {if $info.path_type == 2}checked{/if} >
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label">导航排序</label>
                        <div class="layui-input-inline">
                            <input type="number" name="nav_sort"  value="{$info.nav_sort}" class="layui-input">
                        </div>
                    </div>

                <input type="hidden" name="nav_id" value="{$info.nav_id}">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" type="button" lay-submit="" lay-filter="zz_edit">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form','iconPickerFa'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery;

        var type = "{$info.nav_type}";

        if(type == 1){
            $("#path").show();
            $("#path_type").show();
        }else{
            $("#path").hide();
            $("#path_type").hide();
        }

        // 监听单选导航类型
        form.on("radio(type)",function(data){
            if(data.value== 2){
                $("#path").hide();
                $("#path_type").hide();
            }else{
                $("#path").show();
                $("#path_type").show();
            }
        });
        // 监听所属位置
        form.on("select(seat)",function(data){
            $.ajax({
                url : '/back/nav/getNavLists',
                data:{seat_id:data.value},
                type:'GET',
                beforeSend:function(){
                    layer.msg('正在获取所属导航',{icon:16,shade:0.8});
                },
                success:function(res){
                    if(res.code == 1){
                         $("#nav").find("option").remove();
                         $("#nav").append("<option value='0'>顶级导航</option>");
                        for(var i = 0; i < res.data.length;i++){
                            $("#nav").append("<option value='"+res.data[i].nav_id+"'>" + res.data[i].nav_name + "</option>");
                        }
                        form.render();
                    }else{
                        layer.msg(res.msg,{icon:2});
                    }
                }
            });

            return false;
        });


        //监听提交
        form.on('submit(zz_edit)', function (data) {
            data = data.field;
            $.ajax({
                url : '/back/nav/edit',
                data :data,
                type:'POST',
                success:function(res){
                    if(res.code == 1){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(res.msg,{icon:2});
                    }

                }
            });
            return false;
        });



    });
</script>

</body>
</html>